<?php

class Utils {
	
	/**
	 * Returns the value from the given array if it exists, defaultValue otherwise
	 * 
	 * @param array $array
	 * @param mixed $key If its an array, will test for every element
	 * @param mixed $defaultValue Value to be returned if key does not exist
	 * @return mixed
	 */
	public static function vget(array $array, $key, $defaultValue = null) {
		// array behaviour
		if (is_array($key)) {
			foreach ($key as $keyValue) {
				if (isset($array[$keyValue]) || array_key_exists($keyValue, $array)) return $array[$keyValue];
			}
			
			return $defaultValue;
		}
		
		// normal behaviour
		return isset($array[$key]) || array_key_exists($key, $array) ? $array[$key] : $defaultValue;
	}
	
	public static function construct($class, array $contructors) {
		$reflector = new ReflectionClass($class);
		return $reflector->newInstanceArgs($contructors);
	}
}
